#ifndef SERIALPORT_H
#define SERIALPORT_H

#include <QtCore>

#define PORT_QSIZE 0x100

class SerialPort : public QObject
{
    Q_OBJECT
public:
    SerialPort();
    virtual ~SerialPort();

    void init(QString portname, int baudrate);
    bool open(void);
    bool close(void);
    int  read(char *buffer, int length);
    int  send(const char *buffer, int length);
    bool isOpen(void);

    int  getHandle(void);
    int  bytesAvailable(void);
    int  getByte(char *byte);
    QByteArray *readAll();

private:
    QString     portName;
    int         baudRate;
    bool        isopen;

    char        buffer[PORT_QSIZE];
    QByteArray  barry;
    int         bytes;

public:
    QMutex      mutex;

};

#endif // SERIALPORT_H
